﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【在用绳附件】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto在用绳附件
    /// </summary>
    public abstract class AutoUsingWireropeAttrMapping : BaseMapping<UsingWireropeAttr, UsingWireropeAttrModel, UsingWireropeAttrFilterModel>
    {
        public AutoUsingWireropeAttrMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override UsingWireropeAttrModel Entity2Model(UsingWireropeAttr entity)
        {
            UsingWireropeAttrModel model = new UsingWireropeAttrModel();

            model.UsingWireropeAttrID = entity.UsingWireropeAttrID;
            model.GroupInfoID = entity.GroupInfoID;
            model.UsingWireropeID = entity.UsingWireropeID;
            model.Code = entity.Code;
            model.AttrFileName = entity.AttrFileName;
            model.AttrFileUrl = entity.AttrFileUrl;
            model.Remark = entity.Remark;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override UsingWireropeAttr Model2Entity(UsingWireropeAttrModel model)
        {
            UsingWireropeAttr entity = new UsingWireropeAttr();

            entity.UsingWireropeAttrID = model.UsingWireropeAttrID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.UsingWireropeID = model.UsingWireropeID;
            entity.Code = model.Code;
            entity.AttrFileName = model.AttrFileName;
            entity.AttrFileUrl = model.AttrFileUrl;
            entity.Remark = model.Remark;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<UsingWireropeAttr> FilterModel2Where(UsingWireropeAttrFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._UsingWireropeAttrID.HasValue)
            {
                where = where.And(x => x.UsingWireropeAttrID == filterModel._UsingWireropeAttrID.Value);
            }
            if (filterModel._UsingWireropeAttrIDs.IsNotEmpty() && filterModel._UsingWireropeAttrIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeAttrIDs.Contains(x.UsingWireropeAttrID));
            }
            if (filterModel._NotUsingWireropeAttrIDs.IsNotEmpty() && filterModel._NotUsingWireropeAttrIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeAttrIDs.Contains(x.UsingWireropeAttrID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //在用绳
            if (filterModel._UsingWireropeID.HasValue)
            {
                where = where.And(x => x.UsingWireropeID == filterModel._UsingWireropeID.Value);
            }
            if (filterModel._UsingWireropeIDs.IsNotEmpty() && filterModel._UsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeIDs.Contains(x.UsingWireropeID));
            }
            if (filterModel._NotUsingWireropeIDs.IsNotEmpty() && filterModel._NotUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeIDs.Contains(x.UsingWireropeID));
            }

            //附件编码
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //文件名
            if (!string.IsNullOrEmpty(filterModel._AttrFileName))
            {
                where = where.And(x => x.AttrFileName.Contains(filterModel._AttrFileName));
            }
            if (!string.IsNullOrEmpty(filterModel._AttrFileNameEqual))
            {
                where = where.And(x => x.AttrFileName == filterModel._AttrFileNameEqual);
            }

            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

